Previous topicNext topic
Help > Keyword Reference >
SEEK statement

Purpose

Set the position in a file for the next input or output operation.

Syntax

SEEK [#] filenum&, position&&

Remarks

SEEK sets the file pointer position of file filenum& to position&&. position&& is a Quad-integer variable, constant, or expression.

The next GET$ or PUT$ performed on the file filenum& will occur position&& bytes (or records) deep into the file. If file filenum& was opened in binary or sequential mode, position&& indicates the new file position in bytes; for random-access files, position is in records.

The first byte position (for binary and sequential files) or record position (for random-access files) may be 0 or 1, depending on the BASE option used when the file was initially Opened. If no BASE was specified, the default position is 1.

Use the SEEK function to determine a binary file's current pointer position, and LOF to determine its length. Seeking past the end of a file does not produce an error, but no data can be read from beyond the true end of the file.

See also

EOF, FILEATTR, GET$, GET$$, LOC, LOF, OPEN, PUT$, PUT$$, SEEK function, SETEOF

Example

SUB CreateFile

 ' Open a binary file and writes 75 chars to it.

 LOCAL I&

 OPEN "SEEK.DTA" FOR BINARY AS #1

 FOR I& = 48 TO 122

   PUT$ 1, CHR$(I&)

 NEXT I&

END SUB

 

FUNCTION ReadIt$(Start&&, qSize&&)

 ' SEEK to the correct position in the file,

 ' which was previously opened in the CreateFile SUB.

 SEEK 1, Start&&

 I&& = 1

 TempStr$ = ""

 ' Read in the indicated data - don't read past end of file.

 WHILE (ISFALSE EOF(1)) AND (I&& <= qSize&&)

   GET$ 1, 1, Char$

   TempStr$ = TempStr$ + Char$

   INCR I&&

 WEND

 ReadIt$ = TempStr$    ' assign function's result

END FUNCTION